package com.lx.boot1;

import com.lx.util.LX;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;

@Slf4j
public class GetMaven {
    public static void main(String[]args){
        String appname = "lxboot3";
        String version = "1.12.9";
//        String appname = "lx";
//        String version = "2.2.4";
        for (int i = 0; i < 20; i++) {
            String center = LX.http("https://repo1.maven.org/maven2/io/github/52ylx/"+appname+"/"+version+"/").send();
            if (!center.contains("<title>404 Not Found</title>")){
                log.info(version+".中心仓库 更新完成!");
                break;
            }
            LX.sleep(300000);
        }
        getJar(appname, version);
    }

    public static boolean getJar(String appname, String version){
        Random random = new Random();
        boolean jar = false;
        boolean pom = false;
        for (int i = 0; i < 10000; i++) {
            if (!jar){
                String s = LX.http("https://maven.aliyun.com/nexus/content/repositories/central/io/github/52ylx/"+appname+"/"+version+"/"+appname+"-"+version+".jar").send();
                System.out.println(s);
                if (!s.contains("404")){
                    jar = true;
                }
            }
            if (!pom){
                String s = LX.http("https://maven.aliyun.com/nexus/content/repositories/central/io/github/52ylx/"+appname+"/"+version+"/"+appname+"-"+version+".pom").send();
                System.out.println(s);
                if (!s.contains("404")){
                    pom = true;
                }
            }
            log.info("进行中... jar:{}  pom:{}", jar, pom);
            if (jar && pom){
                return true;
            }
            LX.sleep(3000+random.nextInt(3000));
        }
        return false;
    }
}
